﻿using Appliaction.Dto.Sinv;
using Appliaction.IAppServices.Sinv;
using Domain.Entitys.Sinv;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace API.Controllers.Sinv
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class Sinv_Sale_OrderController : ControllerBase
    {
        private readonly ISinv_Sale_OrderService sinv_Sale_OrderService;

        public Sinv_Sale_OrderController(ISinv_Sale_OrderService sinv_Sale_OrderService)
        {
            this.sinv_Sale_OrderService = sinv_Sale_OrderService;
        }

        /// <summary>
        /// 查询销售订单及其详情
        /// </summary>
        /// <param name="currendPage"></param>
        /// <param name="pageSize"></param>
        /// <param name="customerName"></param>
        /// <param name="orderCode"></param>
        /// <returns></returns>
        [HttpGet]
        public JsonResult GetSinv_Sale_Infos(int currendPage, int pageSize, string? customerName, string? orderCode, string? proName, int orderStatus, char auditStatus)
        {
            return new JsonResult(sinv_Sale_OrderService.GetSinv_Sale_Infos(currendPage,pageSize,customerName,orderCode, proName,orderStatus,auditStatus));
        }

        /// <summary>
        /// 查询销售订单总数
        /// </summary>
        /// <param name="customerName"></param>
        /// <param name="orderCode"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<JsonResult> Sinv_Sale_OrderCOuntAsync(string? customerName, string? orderCode, string? proName, int orderStatus, char auditStatus)
        {
            return new JsonResult(await sinv_Sale_OrderService.Sinv_Sale_OrderCOuntAsync(customerName,orderCode, proName,orderStatus,auditStatus));
        }

        /// <summary>
        /// 添加销售订单明细和批量添加销售订单明细
        /// </summary>
        /// <param name="saleOrderWithDetailsDto"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<JsonResult> Sinv_Sale_OrderAddAsync([FromBody]SaleOrderWithDetailsDto<Sinv_Sale_OrderAddDto> saleOrderWithDetailsDto)
        {
            return new JsonResult(await sinv_Sale_OrderService.Sinv_Sale_OrderAddAsync(saleOrderWithDetailsDto));
        }

        /// <summary>
        /// 逻辑删除销售订单信息
        /// </summary>
        /// <param name="sinv_Sale_OrderDelDto"></param>
        /// <returns></returns>
        [HttpPut]
        public async Task<JsonResult> Sinv_Sale_OrderDelAsync(Sinv_Sale_OrderDelDto sinv_Sale_OrderDelDto)
        {
            return new JsonResult(await sinv_Sale_OrderService.Sinv_Sale_OrderDelAsync(sinv_Sale_OrderDelDto));
        }

        /// <summary>
        /// 根据销售订单编号查询对应销售订单信息
        /// </summary>
        /// <param name="code"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<JsonResult> GetSinv_Sale_OrderByCodeAsync(string code)
        {
            return new JsonResult(await sinv_Sale_OrderService.GetSinv_Sale_OrderByCodeAsync(code));
        }

        /// <summary>
        /// 根据销售订单编号查询销售明细
        /// </summary>
        /// <param name="code"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<JsonResult> GetSinv_Sale_Order_DetailsByCodeAsync(string code)
        {
            return new JsonResult(await sinv_Sale_OrderService.GetSinv_Sale_Order_DetailsByCodeAsync(code));
        }

        /// <summary>
        /// 修改销售订单及其明细
        /// </summary>
        /// <param name="saleOrderWithDetailsDto"></param>
        /// <returns></returns>
        [HttpPut]
        public async Task<JsonResult> Sinv_Sale_OrderUpdateAsync([FromBody]SaleOrderWithDetailsDto<Sinv_Sale_OrderUpdateDto> saleOrderWithDetailsDto)
        {
            return new JsonResult(await sinv_Sale_OrderService.Sinv_Sale_OrderUpdateAsync(saleOrderWithDetailsDto));
        }

        /// <summary>
        /// 修改销售订单审核状态
        /// </summary>
        /// <param name="_Sale_OrderAuditUpdateDto"></param>
        /// <returns></returns>
        [HttpPut]
        public async Task<JsonResult> Sinv_Sale_OrderAuditUpdateAsync(Sinv_Sale_OrderAuditUpdateDto _Sale_OrderAuditUpdateDto)
        {
            return new JsonResult(await sinv_Sale_OrderService.Sinv_Sale_OrderAuditUpdateAsync(_Sale_OrderAuditUpdateDto));
        }

        /// <summary>
        /// 分页条件查询销售订单信息
        /// </summary>
        /// <param name="currentPage"></param>
        /// <param name="pageSize"></param>
        /// <param name="orderCode"></param>
        /// <param name="status"></param>
        /// <param name="customerName"></param>
        /// <param name="rep_id"></param>
        /// <param name="dept_id"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<JsonResult> Sinv_Sale_OrderSelectAsync(int currentPage, int pageSize, string? orderCode, int status, string? customerName, int rep_id, int dept_id)
        {
            return new JsonResult(await sinv_Sale_OrderService.Sinv_Sale_OrderSelectAsync(currentPage,pageSize,orderCode,status,customerName,rep_id,dept_id));
        }

        /// <summary>
        /// 条件查询销售订单总数
        /// </summary>
        /// <param name="orderCode"></param>
        /// <param name="status"></param>
        /// <param name="customerName"></param>
        /// <param name="rep_id"></param>
        /// <param name="dept_id"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<JsonResult> Sinv_Sale_OrderSelectCountAsync(string? orderCode, int status, string? customerName, int rep_id, int dept_id)
        {
            return new JsonResult(await sinv_Sale_OrderService.Sinv_Sale_OrderSelectCountAsync(orderCode,status,customerName,rep_id,dept_id));
        }

        /// <summary>
        /// 条件查询销售订单明细
        /// </summary>
        /// <param name="currentPage"></param>
        /// <param name="pageSize"></param>
        /// <param name="code"></param>
        /// <param name="productCode"></param>
        /// <param name="measureId"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<JsonResult> GetSinv_Sale_Order_DetailsAsync(int currentPage, int pageSize, string code, string? productCode, int measureId)
        {
            return new JsonResult(await sinv_Sale_OrderService.GetSinv_Sale_Order_DetailsAsync(currentPage,pageSize,code,productCode,measureId));
        }

        /// <summary>
        /// 条件查询销售订单总数
        /// </summary>
        /// <param name="code"></param>
        /// <param name="productCode"></param>
        /// <param name="measureId"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<JsonResult> GetSinv_Sale_Order_DetailsCountAsync(string code, string? productCode, int measureId)
        {
            return new JsonResult(await sinv_Sale_OrderService.GetSinv_Sale_Order_DetailsCountAsync(code,productCode,measureId));
        }
        /// <summary>
        /// 分页条件查询销售订单信息
        /// </summary>
        /// <param name="currentPage"></param>
        /// <param name="pageSize"></param>
        /// <param name="orderCode"></param>
        /// <param name="status"></param>
        /// <param name="customerName"></param>
        /// <param name="rep_id"></param>
        /// <param name="dept_id"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<JsonResult> Sinv_Sale_OrderSelectFillAsync(int currentPage, int pageSize, string? orderCode, int status, string? customerName, int rep_id, int dept_id)
        {
            return new JsonResult(await sinv_Sale_OrderService.Sinv_Sale_OrderSelectFillAsync(currentPage, pageSize, orderCode, status, customerName, rep_id, dept_id));
        }

        /// <summary>
        /// 条件查询销售订单总数
        /// </summary>
        /// <param name="orderCode"></param>
        /// <param name="status"></param>
        /// <param name="customerName"></param>
        /// <param name="rep_id"></param>
        /// <param name="dept_id"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<JsonResult> Sinv_Sale_OrderSelectFillCountAsync(string? orderCode, int status, string? customerName, int rep_id, int dept_id)
        {
            return new JsonResult(await sinv_Sale_OrderService.Sinv_Sale_OrderSelectFillCountAsync(orderCode, status, customerName, rep_id, dept_id));
        }

        /// <summary>
        /// 根据客户名称、销售订单名称、产品名称查询汇总
        /// </summary>
        /// <param name="customerName"></param>
        /// <param name="saleOrserName"></param>
        /// <param name="proName"></param>
        /// <returns></returns>
        [HttpGet]
        public JsonResult GetSinv_Sale_InfosSummary(string? customerName, string? saleOrserName, string? proName)
        {
            return new JsonResult(sinv_Sale_OrderService.GetSinv_Sale_InfosSummary(customerName,saleOrserName,proName));
        }

        /// <summary>
        /// 销售订单撤销
        /// </summary>
        /// <param name="sinv_Sale_Order"></param>
        /// <returns></returns>
        [HttpPut]
        public async Task<JsonResult> Sinv_Sale_OrderRevokeAsync(Sinv_Sale_OrderRevokeDto sinv_Sale_Order)
        {
            return new JsonResult(await sinv_Sale_OrderService.Sinv_Sale_OrderRevokeAsync(sinv_Sale_Order));
        }
    }
}
